$(function() {
  var page = 1
  var pageSize = 5
  var total
  
  render()
  function render() {
    $.ajax({
      url: '/user/queryUser',
      type: 'get',
      data: {
        page : page,
        pageSize : pageSize
      },
      success: function(info) {
        console.log(info)
        $('tbody').html(template('users',info))
        total = info.total;
        $('#paginator').bootstrapPaginator({ 
          /*当前使用的是3版本的bootstrap*/
          bootstrapMajorVersion: 3,
          /*当前页*/
          currentPage: page,
          /*一共多少页*/
          totalPages: Math.ceil(total / pageSize),
          onPageClicked: function(event, originalEvent, type, currentpage) {
            page = currentpage;
            render();
          }
        })
      }
    })
  }

  

  var id;
  var isDelete;
  $('tbody').on('click','button',function() {
    id = $(this).parent().data('id')
    isDelete = $(this).hasClass('btn-success')? 1 : 0
    $('#usersModal').modal('show');
   
  })

  $('.confirm').on('click',function() {

    $.ajax({
      url:'/user/updateUser',
      type:'post',
      data: {
        id : id,
        isDelete : isDelete
      },
      success: function(info){
        if(info.success) {
          render();
        }
      }
    })
    $('#usersModal').modal('hide');
  })


  

    
})